# Copyright 2017 The TensorFlow Authors. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# ============================================================================
# Copyright 2021 Huawei Technologies Co., Ltd
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

from npu_bridge.npu_init import *
import argparse
import os
from src.net import Mode
from src import FlowNet2

def main():

    net = FlowNet2(mode=Mode.TEST)
    # Train on the data
    net.test(
        checkpoint=FLAGS.checkpoint,
        input_a_path=FLAGS.input_a,
        input_b_path=FLAGS.input_b,
        out_path=FLAGS.out,
        save_flo=FLAGS.save_flo
    )

if __name__ == '__main__':
  parser = argparse.ArgumentParser()
  parser.add_argument(
      '--input_a',
      type=str,
      required=True,
      help='Path to first image'
  )
  parser.add_argument(
      '--input_b',
      type=str,
      required=True,
      help='Path to second image'
  )
  parser.add_argument(
      '--out',
      type=str,
      required=True,
      help='Path to output flow result'
  )
  parser.add_argument(
      '--checkpoint',
      type=str,
      default='./checkpoints/FlowNet2/flownet-2.ckpt-0',
      help='checkpoint used in the network'
  )
  parser.add_argument(
      '--save_flo',
      type=bool,
      default=False,
      help='save predicted flo file or not'
  )
  FLAGS = parser.parse_args()

  # Verify arguments are valid
  if not os.path.exists(FLAGS.input_a):
      raise ValueError('image_a path must exist')
  if not os.path.exists(FLAGS.input_b):
      raise ValueError('image_b path must exist')
  if not os.path.isdir(FLAGS.out):
      raise ValueError('out directory must exist')
  main()

